package com.example.curriculum;

import com.example.curriculum.fragment.ClassFragment;
import com.example.curriculum.fragment.ExpenseFragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class RecordActivity extends FragmentActivity implements OnCheckedChangeListener, OnClickListener
{
	private static final String	TAG_REGISTER	= "register";
	private ImageButton			mIbBack;
	private TextView			mTvTitle;

	private RadioGroup			mRadioGroup;
	private RadioButton			mRbClass;
	private RadioButton			mRbExpense;

	private FrameLayout			mFragmentContainer;

	private FragmentManager		fm;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_record);

		initView();
		initClickedListener();
		mRadioGroup.setOnCheckedChangeListener(this);
		initFragment();
		mRadioGroup.check(R.id.rb_class);
	}

	/**
	 * 设置各个控件的点击事件
	 */
	private void initClickedListener()
	{
		// TODO 设置点击事件
		mIbBack.setOnClickListener(this);

	}

	private void initFragment()
	{
		fm = getSupportFragmentManager();

	}

	/**
	 * 初始化布局   找到各个控件
	 */
	private void initView()
	{
		mIbBack = (ImageButton) findViewById(R.id.title_bar_ib_back);
		mRadioGroup = (RadioGroup) findViewById(R.id.content_rg);

		mFragmentContainer = (FrameLayout) findViewById(R.id.record_container);

	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId)
	{
		// TODO Auto-generated method stub
		switch (checkedId)
		{
			case R.id.rb_class:
				FragmentTransaction ct = fm.beginTransaction();
				ct.replace(R.id.record_container, new ClassFragment(), TAG_REGISTER);

				ct.commit();
				break;
			case R.id.rb_expense:
				FragmentTransaction et = fm.beginTransaction();
				et.replace(R.id.record_container, new ExpenseFragment(RecordActivity.this), TAG_REGISTER);

				et.commit();
				break;

			default:
				break;
		}

	}

	@Override
	public void onClick(View v)
	{
		// TODO 点击事件的具体内容
		switch (v.getId())
		{
			case R.id.title_bar_ib_back:// 返回键
				finish();
				break;

			default:
				break;
		}

	}
}
